package controllers

import (
	"blog-server/app/common/request"
	"blog-server/app/common/response"
	"blog-server/app/services"
	"blog-server/global"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type frontController struct {
}

var FrontController = new(frontController)

func (FrontController *frontController) GetAllPageList(c *gin.Context) {
	var form request.FrontGetShareList
	if err := c.ShouldBind(&form); err != nil {
		global.App.Log.Error("参数错误", zap.Any("err", err))
		response.ValidateFail(c, "参数错误")
		return
	}
	list, err := services.FontService.GetArticleList(form)
	if err != nil {
		response.BusinessFail(c, "获取失败")
		return
	} else {
		response.Success(c, list)
	}

}

func (FrontController *frontController) GetPageDetail(c *gin.Context) {
	var form request.FrontGetShareDetail
	if err := c.ShouldBind(&form); err != nil {
		global.App.Log.Error("参数错误", zap.Any("err", err))
		response.ValidateFail(c, "参数错误")
		return
	}
	list, err := services.FontService.GetArticleDetail(form)
	if err != nil {
		response.BusinessFail(c, "获取失败")
		return
	} else {
		response.Success(c, list)
	}
}

// 随机获取数据
func (frontController *frontController) GetPageByRound(c *gin.Context) {
	var form request.FrontGetShareList
	if err := c.ShouldBind(&form); err != nil {
		global.App.Log.Error("参数错误", zap.Any("err", err))
		response.ValidateFail(c, "参数错误")
		return
	}
	list, err := services.FontService.GetArticleRandom(form)
	if err != nil {
		response.BusinessFail(c, "获取失败")
		return
	} else {
		response.Success(c, list)
	}
}
